﻿using Dapper;
using Domain.Entity;
using Domain.Repository;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repository
{
    public class CMRepository : ICMRepository
    {
        private readonly MyDbContext myDbContext;

        public CMRepository(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
        public async Task<int> DeleteCM(int id)
        {
            var CM = await myDbContext.CM.FindAsync(id);
            if (CM != null)
            {
                myDbContext.CM.Remove(CM);
                return await myDbContext.SaveChangesAsync();
            }
            return 0;
        }

        public List<CM> GetCM()
        {
            using (SqlConnection connection = new SqlConnection("server=.;database=HR;user=sa;pwd=cssl#123;Encrypt=False;"))
            {
                string sql = "select * from dbo.CM  ";
                return connection.Query<CM>(sql).ToList();
            }
        }
    }
}
